package com.clip.util;

import java.io.BufferedWriter;
import java.io.StringWriter;
import java.util.Locale;

import freemarker.template.Configuration;
import freemarker.template.Template;

public class FtlUtils {

	public static String stringRender(Object dataModel, String ftlFile){ 
		try{
			Configuration config = Ftl.getConfiguration();
	        StringWriter stringWriter = new StringWriter();
	        BufferedWriter writer = new BufferedWriter(stringWriter);
	        
	        Template template = config.getTemplate(ftlFile, Locale.CHINA, "UTF-8");  
	        template.process(dataModel,writer);  
	        writer.flush();
	        return stringWriter.toString();  
		}catch(Exception e){
			e.printStackTrace();
			throw new IllegalArgumentException("ftl error");
		}
	}

}
